package cn.yiya.shiji.views;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import cn.yiya.shiji.R;
import cn.yiya.shiji.business.ShareTools;

public class ShareDialog extends Dialog implements View.OnClickListener {
	private ShareTools shareTool;
	private String sharemsg;
	private Context mContext;

	private String title;
	private String imageUrl;
	private String url;
	private String content;

	public ShareDialog(Context context, String title, String imageUrl, String url, String content) {
		super(context, R.style.ActionSheetDialogStyle);
		this.mContext = context;
		shareTool = ShareTools.getInstance();
		shareTool.initShare(context);
		this.title = title;
		this.imageUrl = imageUrl;
		this.url = url;
		this.content = content;
	}

	@SuppressLint({"RtlHardcoded", "InflateParams"})
	public Dialog build() {
		View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_new_share, null);
		TextView tvWXZone = (TextView) view.findViewById(R.id.tv_wx_zone);
		tvWXZone.setOnClickListener(this);
		TextView tvWX = (TextView) view.findViewById(R.id.tv_wx);
		tvWX.setOnClickListener(this);
		TextView tvCancel = (TextView) view.findViewById(R.id.tv_cancel);
		tvCancel.setOnClickListener(this);
		setContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
		Window dialogWindow = getWindow();
		dialogWindow.setGravity(Gravity.LEFT | Gravity.BOTTOM);
		WindowManager.LayoutParams lp = dialogWindow.getAttributes();
		lp.width = WindowManager.LayoutParams.MATCH_PARENT;
		dialogWindow.setAttributes(lp);
		return this;
	}


	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.tv_wx_zone:
				shareTool.share(ShareTools.Platform_WXZone, title, imageUrl, url, content);
				break;
			case R.id.tv_wx:
				shareTool.share(ShareTools.Platform_WX, title, imageUrl, url, content);
				break;
			case R.id.tv_cancel:
				break;
			default:
				break;
		}
		dismiss();
	}
}

